package com.itheima.controller;

import com.itheima.config.UserProperties;
import com.itheima.service.UserService;
import com.itheima.user.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/user")
@RefreshScope	//nocas自动刷新配置注解，适合少量配置
public class UserController {

    @Autowired
    private UserService userService;
/*
	@Value("${person.name}")
	private String name;
*/
	@Autowired
	private UserProperties userProperties;

    /***
     * 根据id查询用户详情
     */
    @GetMapping(value = "/{id}")
    public User one(@PathVariable(value = "id") Long id){
        return userService.findById(id);
    }

	@GetMapping("/cf")
	public String getCf(){
		//return "********"+name+"*********";
		String name = userProperties.getName();
		int age = userProperties.getAge();
		return "name:"+name+"age:"+age;
	}

	@GetMapping("/header")
	public String getHeader(@RequestHeader("name") String name){
		return "********header:"+name+"*********";
	}

}
